package member;

import java.io.Reader;
import java.sql.Timestamp;
import java.util.List;
import java.util.ArrayList;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import com.opensymphony.xwork2.ActionSupport;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionContext;

public class memberInfoAction extends ActionSupport implements SessionAware{
	
	public static Reader reader;
	public static SqlMapClient sqlMapper;
	
	private Memberbean param;
	private Memberbean result;
	
	private String m_id;
	private String m_pw;
	
	Map session;
	
	public memberInfoAction() throws Exception{
		reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();
	}
	public String execute() throws Exception{
		param = new Memberbean();
		result = new Memberbean();
		
		param.setM_pw(getM_pw());
		param.setM_id(getM_id());

		ActionContext context=ActionContext.getContext();
		Map<String,Object> session = context.getSession();
		
		if(session.size() > 0){
			String id=(String)session.get("session_m_id");
			result = (Memberbean) sqlMapper.queryForObject("getMember", id);
			
			if(result.getM_pw().equals(m_pw)){
				result = (Memberbean)sqlMapper.queryForObject("getMember",getM_id());
				return SUCCESS;
			}
			else{
				return ERROR;
			}
		}
		return ERROR;

	}
	public Memberbean getParam() {
		return param;
	}
	public void setParam(Memberbean param) {
		this.param = param;
	}
	public Memberbean getResult() {
		return result;
	}
	public void setResult(Memberbean result) {
		this.result = result;
	}
	public String getM_id() {
		return m_id;
	}
	public void setM_id(String m_id) {
		this.m_id = m_id;
	}
	public String getM_pw() {
		return m_pw;
	}
	public void setM_pw(String m_pw) {
		this.m_pw = m_pw;
	}
	public void setSession(Map session) {
		this.session = session;
	}
}